{% extends "devhub/addons/submit/base.html" %}

{% block title %}{{ dev_page_title(_('Upload Add-on'), addon) }}{% endblock %}

{% block primary %}

{% set channel_param = 'listed' if channel == amo.CHANNEL_LISTED else 'unlisted' %}

<form method="post" id="create-addon" class="item new-addon-file" enctype="multipart/form-data"
    data-addon-is-listed="{% if channel_param == 'listed' %}true{% else %}false{% endif %}">
  {% csrf_token %}
  {% if submit_page == 'version' %}
    <h3>{{ _('Where to Host Version') }}</h3>
    {% if submit_page == 'version' and addon.disabled_by_user %}
      {# In the version submit page, if add-on is disabled by user, the view should
         already prevent channel from being "listed". We need to prevent the change
         link from being displayed, it wouldn't work anyway. #}
      {% include "devhub/addons/includes/invisible_channel_warning.html" %}
    {% endif %}
    <p class="addon-submit-distribute">
      {{ channel_choice_text|safe }}
      {% if submit_page == 'version' and not addon.disabled_by_user %}
        <a href="{{ url('devhub.submit.version.distribution', addon.slug) }}?channel={{ channel_param }}">{{ _('Change') }}</a>
      {% endif %}
    </p>
  {% endif %}

  <h3>{{ _('Upload Version') }}</h3>
  <p>
  {% trans %}
    Use the fields below to upload your add-on package. After upload, a series
    of automated validation tests will be run on your file.
  {% endtrans %}
  {% trans max_size=max_upload_size|filesizeformat %}
  The maximum file size accepted is {{ max_size }}. If your add-on is larger than {{ max_size }}, it will fail validation.
  {% endtrans %}
  </p>
  <section id="upload-file">

  <div class="hidden">
    {{ new_addon_form.upload }}
  </div>
  <input type="file" id="upload-addon"
  {% if addon %}
      data-upload-url="{{ url('devhub.upload_for_version', addon.slug, channel_param) }}"
  {% else %}
    {% if channel == amo.CHANNEL_LISTED %}
      data-upload-url="{{ url('devhub.upload') }}"
    {% else %}
      data-upload-url="{{ url('devhub.upload_unlisted') }}"
    {% endif %}
  {% endif %}
  data-max-upload-size="{{ max_upload_size }}"
  >
  {{ new_addon_form.theme_specific }}
  {{ new_addon_form.non_field_errors() }}

    <div class="compatible-apps">
      <label>{{ _('Which applications is this version compatible with?') }}</label>
      {{ new_addon_form.compatible_apps.errors }}
      {{ new_addon_form.compatible_apps }}
    </div>

    {% if is_admin %}
    <div class="admin-settings">
      <label>{{ _('Administrative overrides') }}</label>
      <div>
        <label for="{{ new_addon_form.admin_override_validation.auto_id }}" class="addon-upload-failure-dependant">
          {{ new_addon_form.admin_override_validation }}
          {{ new_addon_form.admin_override_validation.label }}
        </label>
      </div>
    </div>
    {% endif %}

    {% if wizard_url %}
    <div class="submission-buttons addon-create-theme-section">
      <p></p>
      <h3>{{ _('Create a Theme Version') }}</h3>
      <p>
        You can upload a finished theme using the upload option above,
        or you can build it yourself using this tool.
      </p>
      <div>
        <a class="button" id="wizardlink" href="{{ wizard_url }}">{{ _('Create a Theme') }}</a>
      </div>
    </div>
    {% endif %}

    {% if 'recaptcha' in new_addon_form.fields %}
    <p>
      {{ new_addon_form.recaptcha }}
      {{ new_addon_form.recaptcha.errors }}
    </p>
    {% endif %}

    <div id="submission-field" class="submission-buttons addon-submission-field" data-submissions-enabled="{{ submissions_enabled|json }}">
      <button class="addon-upload-dependant" id="submit-upload-file-finish" disabled=disabled type="submit">
        {{ _('Continue') }}
      </button>
    </div>
  </section>
</form>
{% endblock primary %}
